package com.jomoo.css.common.util.client;

import com.jomoo.css.common.util.security.AuthenticationUser;
import com.jomoo.css.common.util.security.AuthorizationLogin;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSONObject;

@FeignClient(contextId = "uaa", value = "runtime", fallback = SYSUAAFallback.class)
public interface SYSUAAFeignClient {
    /**
     * 同步系统资源到uaa
     *
     * @param system 系统资源信息
     * @return
     */
    @PostMapping("/syspssystems/save")
    Boolean syncSysAuthority(@RequestBody JSONObject system);

    /**
     * 用户登录
     *
     * @param authorizationLogin 登录信息
     * @return
     */
    @PostMapping(value = "/uaa/login")
    AuthenticationUser login(@RequestBody AuthorizationLogin authorizationLogin);


    @PostMapping(value = "/uaa/loginbyusername")
    AuthenticationUser loginByUsername(@RequestBody String username);

    @Cacheable(value = "sysuaa_publickey")
    @GetMapping(value = "/uaa/publickey")
    String getPublicKey();

    /**
     * 更新用户角色
     *
     * @param userid
     * @param roleTags
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/sysuserroles/updateuserroles/{userid}/{overwrite}")
    ResponseEntity<Boolean> updateUserRoles(@PathVariable("userid") String userid, @RequestBody(required = false) String roleTags, @PathVariable("overwrite") boolean bOverwrite);

    /**
     * 删除某用户的角色关系
     *
     * @param userids
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/sysuserroles/removeuserroles/{userids}")
    ResponseEntity<Boolean> removeUserRoleByUserIds(@PathVariable("userids") String userids);
}
